package com.hmall.trade.listener;

import com.hmall.common.constants.MqConstants;
import com.hmall.trade.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 支付成功更新订单状态的MQ消费者
 *
 * @Author mr.Du
 * @Date 2025/6/21 2025/6/21
 */
@Slf4j
@Component
public class PayFinishUpdateOrderStatusListener {
    @Autowired
    private IOrderService orderService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstants.PAY_SUCCESS_QUEUE),
            exchange = @Exchange(name = MqConstants.PAY_EXCHANGE_NAME, type = ExchangeTypes.DIRECT),
            key = MqConstants.PAY_SUCCESS_KEY
    ))
    public void payFinishUpdateOrderStatusListener(Long orderId) {
        orderService.markOrderPaySuccess(orderId);
        log.info("支付成功更新订单状态的MQ消费结束");
    }
}
